import { defineStore } from "pinia";
import type { TrademarkType, TrademarkParamsType } from "@/types/trademark";
import { reqGetTrademarkList } from "@/api/trademark";

export interface TrademarkStateType {
    trademarkList: TrademarkType[];
    pages: number;
    total: number;
}

export const useTrademarkStore = defineStore("trademark", {
    // state
    state: (): TrademarkStateType => ({
        trademarkList: [],
        pages: 0,
        total: 0,
    }),
    actions: {
        // 获取品牌列表
        async getTrademarkList({ page, limit }: TrademarkParamsType) {
            try {
                const res = await reqGetTrademarkList({ page, limit });
                this.trademarkList = res.records;
                this.pages = res.pages;
                this.total = res.total;
            } catch (e) {
                return Promise.reject(e);
            }
        },
    },
});
